<?php
//
//  VictoryCMS - Content managment system and framework.
//  Copyright (C) 2009  Lewis Gunsch
//
//  This file is part of VictoryCMS.
//  
//  VictoryCMS is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  VictoryCMS is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with VictoryCMS.  If not, see <http://www.gnu.org/licenses/>.

/**
 * VictoryCMS - DbConnectTest
 * 
 * @license http://www.gnu.org/licenses/gpl.html
 * @author Lewis Gunsch
 * @filesource
 * @package DisplayablePages
 */

/**
 * Tests database connections.
 * 
 * @package DisplayablePages
 */
class DbConnectTest implements DisplayablePage {

	/** @see DisplayablePage#getTitle() */
	public function getTitle() {
		return "Database Connection Test";
	}

	/** @see DisplayablePage#getName() */
	public function getName() {
		return "DB Connect Test";
	}

	/** @see DisplayablePage#getDescription() */
	public function getDescription() {
		return "Tests out the connection to the database";
	}

	/** @see DisplayablePage#getKeywords() */
	public function getKeywords() {
		return "";
	}

	/** @see DisplayablePage#getHeaderInfo() */
	public function getHeaderInfo() {
		return "";
	}

	/** @see DisplayablePage#renderPage() */
	public function renderPage( $currentPage ) {
		$html = "";
		
		$db = VcmsDBFactory::createVcmsDb();
		$db2 = VcmsDBFactory::createVcmsDb();
		
		$db->getConnected();
		$db2->getConnected();
		
		$dbConn = ($db->isConnected() == true)? "true": "false";
		$db2Conn = ($db2->isConnected() == true)? "true": "false";
		
		$html .= "Connection: ". $dbConn ."<br />";
		$html .= "Connection2: ". $db2Conn ."<br />";
		
		$testQueries = new TestQueries();
		$db->runQuery("version", $testQueries);
		print_ar($db->fetchRow());
		$db->runQuery("drop_test_table", $testQueries);
		print_ar($db->fetchRow());
		$db->runQuery("create_test_table", $testQueries);
		print_ar($db->fetchRow());
		$db->runQuery("put_row", $testQueries, 
			array("Olga Kurylenko", "Super hot James Bond girl"));
		print_ar($db->fetchRow());
		$db->runQuery("select_test_table", $testQueries, array("*"));
		print_ar($db->fetchRow());
		
		$html .= "<br />Field Names: ". $db->fetchFieldName(0) .", ".
			$db->fetchFieldName(1). "<br />";
		
		$html .= "<br />Field Types: ". $db->fetchFieldType(0) .", ".
		$db->fetchFieldType(1). "<br /><br />";
		
		$db2->cleanUp();
		$dbConn = ($db->isConnected() == true)? "true": "false";
		$db2Conn = ($db2->isConnected() == true)? "true": "false";
		
		$html .= "2 Connection: ". $dbConn ."<br />";
		$html .= "2 Connection2: ". $db2Conn ."<br />";
		
		$db->cleanUp();
		$dbConn = ($db->isConnected() == true)? "true": "false";
		$db2Conn = ($db2->isConnected() == true)? "true": "false";
		
		$html .= "3 Connection: ". $dbConn ."<br />";
		$html .= "3 Connection2: ". $db2Conn ."<br />";
		
		return $html;
	}

	/** @see DisplayablePage#pagePreProcess() */
	public function pagePreProcess() {
		return;
	}

	/** @see DisplayablePage#getPagePermissionLevel() */
	public function getPagePermissionLevel() {
		return new Permission("anonymous");
	}
}
?>